//
//  DYShareView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/13.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYShareView.h"

@interface DYShareView ()

@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIImageView *topImageView;
@property (nonatomic,strong)UIView *codeBgView;
@property (nonatomic,strong)UIImageView *codeImageView;
@property (nonatomic,strong)UILabel *inviteCodeLabel;
@property (nonatomic,strong)UIButton *inviteButton;
@property (nonatomic,strong)UILabel *tipLabel;

@end


@implementation DYShareView


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    self.backgroundColor=[UIColor xhq_base];
    
    self.scrollView = ({
        UIScrollView *view=[[UIScrollView alloc]init];
        view.alwaysBounceVertical=YES;
        view;
    });
    
    self.bgImageView = ({
        UIImageView *imageView=[Utils imageViewWithImage:IMG(@"img_bg_invite")];
        imageView.contentMode=UIViewContentModeScaleAspectFill;
        imageView;
    });
    
    
    self.topImageView = ({
        UIImageView *imageView=[Utils imageViewWithImage:IMG(@"words_invite")];
//        imageView.contentMode=UIViewContentModeScaleToFill;
        imageView;
    });
    
    self.codeBgView = ({
        UIView *view=[[UIView alloc]init];
        view.backgroundColor=WhiteColor;
        view;
    });
    
    self.codeImageView = ({
        UIImageView *imageView=[Utils imageView];
        imageView;
    });
    
    self.inviteCodeLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:WhiteColor alignment:1];
        label;
    });
    
    self.inviteButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(inviteButtonClick) target:self title:@"分享给朋友" image:nil font:17 textColor:[UIColor xhq_base]];
        [button  setBackgroundImage:IMG(@"btn_invite") forState:UIControlStateNormal];
        button;
    });
    
    self.tipLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:WhiteColor alignment:0];
        label;
    });
    
    [self addSubview:self.scrollView];
    
    [self.scrollView addSubview:self.bgImageView];
    [self.scrollView addSubview:self.topImageView];
    [self.scrollView addSubview:self.codeBgView];
    [self.codeBgView addSubview:self.codeImageView];
    [self.scrollView addSubview:self.inviteCodeLabel];
    [self.scrollView addSubview:self.inviteButton];
    [self.scrollView addSubview:self.tipLabel];
    
 
    [self.scrollView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(0);
    }];
    
    [self.bgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.width.equalTo(kScreenWidth);
        make.top.equalTo(0);
        make.height.equalTo(kScreenHeight-kNavigationStatusHeight);
    }];
    
    [self.topImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(BILIHEIGHT(35));
        make.centerX.equalTo(self);
    }];
    
    [self.codeBgView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.topImageView.bottom).offset(BILIHEIGHT(70));
        make.width.height.equalTo(BILIWIDTH(128));
    }];
    
    [self.codeImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.codeBgView);
        make.width.height.equalTo(BILIWIDTH(105));
    }];
    
    [self.inviteCodeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.codeBgView.bottom).offset(BILIHEIGHT(13));
        make.centerX.equalTo(self);
    }];
    
    [self.inviteButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.inviteCodeLabel.bottom).offset(BILIHEIGHT(50));
        make.size.equalTo(CGSizeMake(BILIWIDTH(355), BILIHEIGHT(38)));
    }];
    
    [self.tipLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inviteButton.bottom).offset(BILIHEIGHT(15));
        make.width.equalTo(BILIWIDTH(355));
        make.centerX.equalTo(self);
    }];
    
    
    self.inviteCodeLabel.text=@"GR34242GJ";
    self.tipLabel.text=@"邀请说明：\n卡福智能管家成立于1983年，是大卖场业态的首创者，是欧洲第一大零售商，世界第二大国际化零售。";
    self.tipLabel.attributedText=[DYAppCommon getRange:NSMakeRange(0, @"邀请说明：".length) labelStr:self.tipLabel.text Font:kFont(15) Color:WhiteColor];
    [self.tipLabel xhq_lineSpace:BILIHEIGHT(5)];
    
    [self layoutIfNeeded];
    
    self.scrollView.contentSize=CGSizeMake(0, self.tipLabel.xhq_bottom+BILIHEIGHT(20));
}
-(void)inviteButtonClick
{
    !self.shareBlock?:self.shareBlock();
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
